﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace AudioPlayer.GUI.Splitter {
	internal class Split : System.Windows.Forms.SplitContainer {
		#region Variables
		private Color _colorSplit;
		#endregion
		#region Constructor
		public Split() {
			Init();
		}
		#endregion
		#region Private Voids
		private void Init() {
			InitControl();
			InitStyle();
		}
		private void InitControl() {
			this.SplitterWidth = 1;
			this.ResizeRedraw = true;
			this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer
				| ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
			this.Panel1MinSize = 20;
			this.SplitterDistance = this.Distance;

			this.SplitterMoved += new SplitterEventHandler(Split_SplitterMoved);
		}
		private void InitStyle() {
			_colorSplit = Color.FromArgb(80, 117, 167);
			this.BackColor = _colorSplit;
		}
		private void Draw(Graphics g) {
			//Double buffer
			Bitmap bmp = new Bitmap(this.SplitterRectangle.Width+1, this.SplitterRectangle.Height);
			SolidBrush brush = new SolidBrush(_colorSplit);
			Graphics gr = Graphics.FromImage(bmp);
			//Draw to buffer
			gr.FillRectangle(brush, new Rectangle(0,0,this.SplitterRectangle.Width+1,this.SplitterRectangle.Height));
			//Draw to graphics
			g.DrawImage(bmp, this.SplitterRectangle.Location);
			//Clean up
			brush.Dispose();
			gr.Dispose();
			bmp.Dispose();
		}
		#endregion
		#region Public Voids

		#endregion
		#region Override
		protected override void OnPaint(PaintEventArgs e) {
			//Don't allow to draw while in design mode.
			if (!this.DesignMode) {
				//this.Draw(e.Graphics);
			}
		}
		#endregion
		#region Event Handling
		private void Split_SplitterMoved(object sender, SplitterEventArgs e) {
			this.Distance = this.SplitterDistance;
		}
		#endregion
		#region Property
		/// <summary>
		/// Gets or sets the splitter distance.
		/// </summary>
		/// <value>The distance.</value>
		public int Distance {
			get {
				return Config.Settings.Cache.Get<int>("SplitterDistance", 90);
			}
			set {
				Config.Settings.Cache.Set<int>("SplitterDistance", value);
			}
		}
		#endregion
	}
}
